package se.webbzon.oschi01.worldobject.appearance;

import java.util.Collections;
import java.util.List;

public class SimpleGroupAppearance3D extends GroupAppearance3D {
	
	// A collection of all appearances in this simple group appearance
	private final List<Appearance3D> appearances;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public SimpleGroupAppearance3D(List<Appearance3D> appearances) {
		this(0,appearances);
	}
	
	public SimpleGroupAppearance3D(int renderingOrder, List<Appearance3D> appearances) {
		this(renderingOrder,0,appearances);
	}
	
	public SimpleGroupAppearance3D(	int renderingOrder, 
									int groupAppearanceProperties, 
									List<Appearance3D> appearances) {
		super(renderingOrder,groupAppearanceProperties,appearances);
		this.appearances = appearances;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public boolean addAppearance(Appearance3D appearance) {
		if (super.addAppearance(appearance))
			return appearances.add(appearance);
		else
			return false;
	}
	
	@Override public boolean removeAppearance(Appearance3D appearance) {
		if (super.removeAppearance(appearance))
			return appearances.remove(appearance);
		else
			return false;
	}
	
	/** Returns the number of appearances in this simple appearance group. **/
	public int size() {
		return appearances.size();
	}
	
	/** Returns the appearance at the given index in this 
	 * simple appearance group. **/
	public Appearance3D getAppearance(int index) {
		return appearances.get(index);
	}
	
	/** Returns a list of all appearances in this simple appearance group. **/
	public List<Appearance3D> getAppearances() {
		return Collections.unmodifiableList(appearances);
	}
	
	@Override public void onStepEnd() {
		super.onStepEnd();
		for (Appearance3D appearance : appearances)
			appearance.onStepEnd();
	}

}
